package org.jaronsource.framework.plugins.security.web.taglib;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import org.jaronsource.framework.plugins.security.SecurityTokenHolder;
import org.jaronsource.framework.plugins.security.domain.SecurityToken;

public class SecurityUserTag extends TagSupport {

	private static final long serialVersionUID = -1299072346487791374L;

	private String var = "SECURITY_USER";

	public String getVar() {
		return var;
	}

	public void setVar( String var ) {
		this.var = var;
	}

	@Override
	public int doStartTag() throws JspException {

		SecurityToken token = SecurityTokenHolder.getSecurityToken();
		if ( token != null ) pageContext.setAttribute( var, token.getUser() );
		return SKIP_BODY;
	}
}
